package com.linq.cool.api.factory;

import com.linq.cool.api.domain.SysFile;
import com.linq.cool.api.feign.RemoteFileService;
import com.linq.cool.common.core.domain.Result;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: yqlin
 * @Date: 2021/1/2 14:24
 * @Description: 文件服务降级处理
 * @Version: 1.0.0
 */
@Component
@Slf4j
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
    @Override
    public RemoteFileService create(Throwable throwable) {
        log.error("The file service invocation failed:{}", throwable.getMessage());
        return new RemoteFileService() {
            @Override
            public Result<SysFile> upload(MultipartFile file) {
                return Result.fail("上传文件失败");
            }
        };
    }
}
